% 窗函数法
wp=0.3*pi;                          
ws=0.4*pi;
deltaw = ws-wp;                     
N = ceil(1.8*pi/deltaw);    %滤波器长度        
wc = (wp+ws)/2;             %理想低通滤波器的截止频率                 
hd = ideallp(wc,N);         %理想滤波器的单位冲击响应

wd1 = boxcar(N)';           %矩形窗              
h1 = hd.*wd1;               %加窗         
[H1,w] = freqz(h1,1);     
figure(1)
stem(hd)
title('单位脉冲响应')
figure(2)
plot(w/pi,20*log10(abs(H1)));
title('矩形窗');

function my_output=ideallp(wc,N)
% 单位冲击响应
alpha = (N-1)/2;
n = 0:1:(N-1);
m = n-alpha+eps;
my_output = sin(wc*m)./(pi*m);
end
